﻿
<form id="roleForm" lay-filter="system-role-form" class="layui-form model-form">
    <input name="id" type="hidden"/>
    <input name="createTime" type="hidden"/>
    <div class="layui-form-item">
        <label class="layui-form-label">角色名</label>
        <div class="layui-input-block">
            <input name="name" placeholder="请输入角色名" type="text" class="layui-input" maxlength="20"
                   lay-verify="required" required/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">备注</label>
        <div class="layui-input-block">
            <textarea name="comment" placeholder="请输入内容" class="layui-textarea" maxlength="200"></textarea>
        </div>
    </div>
    <div  style="display: none">
        <button class="layui-btn" lay-filter="system-role-submit" id = "system-role-submit" lay-submit>保存</button>
    </div>
</form>

<script>
    layui.use(['layer', 'form', 'admin','util'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var admin = layui.admin;
        var util = layui.util;
        var url = 'system/role/add';
        // 回显数据
        var role = admin.getTempData('system-role-obj');
        if (role) {
            url = 'system/role/update';
            form.val('system-role-form', role);
            $('#system-role-form input[name="createTime"]').val(util.toDateString(role.createTime));

        }
        // 表单提交事件
        form.on('submit(system-role-submit)', function (data) {
            console.log(data);
            admin.req(url,data.field,function(data){
                layer.msg("保存角色成功", {icon: 1});
                admin.putTempData('system-role-formOk', true);  // 操作成功刷新表格
                layer.close(layer.curr_idex);
            },"post");
            return false;
        });

    });
</script>

</body>
</html>